package net.brokenroad.gamma.net;

import java.io.*;

public class Packet implements Serializable
{
	private static final long serialVersionUID = 5876092694764293815L;

	public enum PacketType
	{
		AUTH, CHANGE, CHAT, DETAILS, FAILURE, JOIN, LIST, REQUEST_INFO, SUCCESS, QUIT, VERSION
	};

	PacketType type;
	String detail1;
	String detail2;
	int[] details;

	public Packet(PacketType type)
	{
		this(type, "");
	}

	public Packet(PacketType type, String param1)
	{
		this(type, param1, "");
	}

	public Packet(PacketType type, String param1, String param2)
	{
		this(type, param1, param2, new int[]
		{0});
	}

	public Packet(PacketType type, String param1, String param2, int int1,
	    int int2, int int3, int int4, int int5)
	{
		this.type = type;
		detail1 = param1;
		detail2 = param2;
		details = new int[5];
		details[0] = int1;
		details[1] = int2;
		details[2] = int3;
		details[3] = int4;
		details[4] = int5;
	}

	public Packet(PacketType type, String param1, String param2, int[] params)
	{
		this.type = type;
		detail1 = param1;
		detail2 = param2;
		details = params;
	}

	public String toString()
	{
		return toString(false);
	}

	public String toString(boolean detailed)
	{
		if (!detailed)
			return "{" + type + ", \"" + detail1 + "\", \"" + detail2 + "\"}";

		String str = "net.brokenroad.gamma.net.Packet[";
		str += "type=" + type;
		str += ", detail1=\"" + detail1 + "\"";
		str += ", detail2=\"" + detail2 + "\"";
		if (details != null && details.length > 0)
		{
			str += ", details={" + details[0];
			for (int i = 1; i < details.length; i++)
				str += "," + details[i];
			str += "}";
		}

		str += "]";
		return str;
	}

	public String toHTML()
	{
		String str = "<b>Type:</b> " + type + "<br>";
		str += "<b>String1:</b> " + detail1 + "<br>";
		str += "<b>String2:</b> " + detail2 + "<br>";
		for (int i = 0; i < details.length; i++)
			str += "<b>int" + i + ":</b> " + details[i] + "<br>";

		return str;
	}

	public PacketType getType()
	{
		return type;
	}

	public String getDetail1()
	{
		return detail1;
	}

	public String getDetail2()
	{
		return detail2;
	}

	public int[] getDetails()
	{
		return details;
	}

	public void setDetail1(String detail1)
	{
		this.detail1 = detail1;
	}

	public void setDetail2(String detail2)
	{
		this.detail2 = detail2;
	}

	public void setDetails(int[] details)
	{
		this.details = details;
	}

	public void setType(PacketType type)
	{
		this.type = type;
	}
}
